package cn.itcast.reggie.service.impl;

import cn.itcast.reggie.common.R;
import cn.itcast.reggie.dto.DishDto;
import cn.itcast.reggie.mapper.DishFlavorMapper;
import cn.itcast.reggie.mapper.DishMapper;
import cn.itcast.reggie.pojo.Dish;
import cn.itcast.reggie.pojo.DishFlavor;
import cn.itcast.reggie.service.DishService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

@Service
@Slf4j
@Transactional
public class DishServiceImpl extends ServiceImpl<DishMapper, Dish> implements DishService {

    @Autowired
    private DishFlavorMapper dishFlavorMapper;

    @Override
    public void add(DishDto dishDto) {
        this.save(dishDto);//保存菜品基本信息
        //保存口味；
        List<DishFlavor> flavors = dishDto.getFlavors();
        for (DishFlavor flavor : flavors) {
            flavor.setDishId(dishDto.getId());
            dishFlavorMapper.insert(flavor);
        }


    }




}